package cn.tedu.tw.hjl.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class AppjdbcSelect {
    public static void main(String[] args) throws Exception {
        //1.加载驱动
            Class.forName("com.mysql.jdbc.Driver");
        //2.获取链接
         String url = "jdbc:mysql://localhost:3306/text?useSSL=false";
         String username = "root";
         String password = "root";
        Connection connection = DriverManager.getConnection(url,username,password);
         //3.创建陈述句对象
        Statement statement = connection.createStatement();
        //4.执行查询
        //order by id 意思是：按照id排列，默认升序
        String sql = "SELECT `id`,`username`,`password` FROM `user` ";
        ResultSet set = statement.executeQuery(sql);
        //5.获取数据
        while (set.next()) {
            String V= set.getString(2);
            String  id = set.getString(1);
            String pw = set.getString(3);
            System.out.println("id is : " + id+",username is :" + V+" password is :" + pw );
        }
    }
}
